package com.abe.libcore.core.screen;

import com.abe.libcore.utils.normal.ToastUtils;
import com.abe.mvpcore.BasePresenter;
import com.abe.mvpcore.BaseView;
import com.abe.mvpcore.PresenterHelper;

public abstract class MvpBaseActivity extends BaseActivity {

    protected BasePresenter getPresenter(Class<?> presenterClass) {
        BaseView view = isImp() ? (BaseView) this : new BaseView() {
            @Override
            public void onFinish(Object type) {

            }

            @Override
            public void onFailure(Object type) {

            }
        };
        if (!isImp()) {
            String message = presenterClass.getName() + "View Not Found";
            ToastUtils.show(message);
        }
        return (BasePresenter) PresenterHelper.getInstance().getPresenter(presenterClass, view);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (isImp())
            PresenterHelper.getInstance().destroy((BaseView) this);
    }

    private boolean isImp() {
        Class clazz = this.getClass();
        Class aClass = BaseView.class;
        return aClass.isAssignableFrom(clazz);
    }
}
